import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import './assets/theme/theme-darkblue/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
import routes from './routes'
// import 'font-awesome/css/font-awesome.min.css' // index.html引入了
import util from './common/js/util'

Vue.prototype.$util = util; //注册全局方法

Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)
// 引入axios，并加到原型链中
import axios from 'axios'
Vue.prototype.$axios = axios;

const router = new VueRouter({
  routes
})

// import { getRules } from "./api/permissionApi"


router.beforeEach((to, from, next) => {
  //NProgress.start();
  // console.log(routes)
  if (to.path === '/login') {
    sessionStorage.removeItem('user');
  }
  let user = JSON.parse(sessionStorage.getItem('user'));
  if (!user && to.path !== '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
  // getRules().then(res => {
  //   console.log(res.data.rules)
  //   let rules = res.data.rules
  //   if (rules.includes('*')) {
  //     return
  //   }
  //   if (!rules.includes('admin/activity')) {
  //     routes[4].hideen = true
  //   }
  //   if (!rules.includes('admin/member')) {
  //     routes[5].hideen = true
  //   }
  //   if (!rules.includes('admin/order')) {
  //     routes[6].hideen = true
  //     routes[7].hideen = true
  //   }
  //   if (!rules.includes('admin/finance')) {
  //     routes[8].hideen = true
  //   }
  //
  // }).catch(err => {
  //   console.log(err)
  //   if (err.response.data.code === 4) {
  //     routes.splice(5)
  //   }
  // })


})

new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  store,
  //components: { App }
  render: h => h(App)
}).$mount('#app')

